package com.bindapp.widget;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import com.github.mikephil.charting.components.IMarker;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;

/**
 * Created by apple on 2018/7/2.
 */

public class MarkView implements IMarker {
    private Paint paint;
    private float val;

    public MarkView(){
        paint=new Paint();
        paint.setColor(Color.argb(200,6,102,102));
        paint.setAntiAlias(true);
        paint.setTextSize(40);
        paint.setStyle(Paint.Style.FILL);
        paint.setTextAlign(Paint.Align.CENTER);
    }
    @Override
    public MPPointF getOffset() {
        return null;
    }

    @Override
    public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {
        return new MPPointF(posX,posY);
    }

    @Override
    public void refreshContent(Entry e, Highlight highlight) {
        val=e.getY();
    }

    @Override
    public void draw(Canvas canvas, float posX, float posY) {
        Paint.FontMetrics fontMetrics = paint.getFontMetrics();
        float top = fontMetrics.top;//为基线到字体上边框的距离,即上图中的top
        float bottom = fontMetrics.bottom;//为基线到字体下边框的距离,即上图中的bottom
        canvas.drawText(""+val,posX,posY-(bottom-top)/2,paint);
    }
}
